package com.example.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.backend.entity.BookletVO;
import com.example.backend.entity.SharedBooklet;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 李月
 * @date 2022/5/4 16:52
 */
@Mapper
public interface SharedBookletMapper extends BaseMapper<SharedBooklet> {
    /**
     * @param page 翻页对象
     * @return
     */
    @Select("SELECT tb_booklet.booklet_id AS bookletId,tb_booklet.booklet_name AS bookletName,tb_booklet.create_date AS createDate FROM tb_booklet,tb_shared_booklet WHERE tb_booklet.booklet_id=tb_shared_booklet.booklet_id")
    List<BookletVO> getBooklet(Page<BookletVO> page);

    @Select("SELECT * FROM tb_shared_booklet WHERE booklet_id=#{bookletId}")
    SharedBooklet getSharedBooklet(@Param("bookletId") int bookletId);

    @Delete("DELETE FROM tb_shared_booklet WHERE booklet_id=#{bookletId}")
    void deleteSharedBooklet(@Param("bookletId") int bookletId);

//    @Select("SELECT * FROM tb_shared_booklet,tb_collection WHERE tb_shared_booklet.shared_id=tb_collection.shared_id AND tb_shared_booklet.booklet_id=#{bookletId} AND tb_collection.user_id=#{userId}")
//    SharedBooklet getSharedBookletOrNot(@Param("bookletId") int bookletId, @Param("userId") int userId);
}
